// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from "axios";
import {Base64} from "js-base64";


Vue.config.productionTip = false

axios.interceptors.request.use(function (request) {

  request.headers['Content-Type'] = 'application/cjcenc;charset=UTF-8';
  request.headers['Accept'] = 'application/json, text/plain, */*';

  request.data = Base64.encode(JSON.stringify(request.data));
   
  console.log(request);
  return request;
}, function (error) {
  return Promise.reject(error);
});


axios.interceptors.response.use(function (response) {
  if(response.status != 200){
    // dealError(response.status,response.data.message);
    return Promise.reject({response});
  }
  if('application/cjcenc' == response.headers['content-type']){
    response.data = JSON.parse(Base64.decode(response.data));
  }
  // console.log(response);
  return response;
}, function (e) {
  const { status,data } = e.response;
  // dealError(status , data.message);
  return Promise.reject(e);
});

Vue.prototype.$axios=axios;


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
